<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span><span class="comment doc">/**
<span class="lineno" id="2">     2  </span> * com.sekati.ui.Image
<span class="lineno" id="3">     3  </span> * @version 2.5.5
<span class="lineno" id="4">     4  </span> * @author jason m horwitz | sekati.com
<span class="lineno" id="5">     5  </span> * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
<span class="lineno" id="6">     6  </span> * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
<span class="lineno" id="7">     7  </span> */</span>
<span class="lineno" id="8">     8  </span> 
<span class="lineno" id="9">     9  </span><span class="key">import</span> com.sekati.display.CoreClip;
<span class="lineno" id="10">    10  </span><span class="key">import</span> com.sekati.transitions.Mot;
<span class="lineno" id="11">    11  </span><span class="key">import</span> com.sekati.utils.Delegate;
<span class="lineno" id="12">    12  </span><span class="key">import</span> caurina.transitions.Tweener;
<span class="lineno" id="13">    13  </span>
<span class="lineno" id="14">    14  </span><span class="comment doc">/**
<span class="lineno" id="15">    15  </span> * image loader. Required: mc_tween2
<span class="lineno" id="16">    16  </span> */</span>
<span class="lineno" id="17">    17  </span><span class="key">class</span> com.sekati.ui.Image <span class="key">extends</span> CoreClip {
<span class="lineno" id="18">    18  </span><span class="lineno" id="19">    19  </span>	<span class="key">var</span> img:MovieClip;
<span class="lineno" id="20">    20  </span>	<span class="key">var</span> box:MovieClip;
<span class="lineno" id="21">    21  </span>	<span class="key">var</span> spinner:MovieClip;
<span class="lineno" id="22">    22  </span><span class="lineno" id="23">    23  </span>	<span class="comment">// constructor</span>
<span class="lineno" id="24">    24  </span>	<span class="key">private</span> <span class="key">function</span> Image() {
<span class="lineno" id="25">    25  </span>	}
<span class="lineno" id="26">    26  </span><span class="lineno" id="27">    27  </span>	<span class="comment doc">/**
<span class="lineno" id="28">    28  </span>	 * init called via CoreClip onLoad event
<span class="lineno" id="29">    29  </span>	 * @return Void
<span class="lineno" id="30">    30  </span>	 */</span>
<span class="lineno" id="31">    31  </span>	<span class="key">private</span> <span class="key">function</span> configUI():Void {
<span class="lineno" id="32">    32  </span>		_this.spinner._visible = <span class="key">false</span>;
<span class="lineno" id="33">    33  </span>	}
<span class="lineno" id="34">    34  </span><span class="lineno" id="35">    35  </span>	<span class="comment doc">/**
<span class="lineno" id="36">    36  </span>	 * wrapper for setup and init methods
<span class="lineno" id="37">    37  </span>	 * @param uri (String) image uri
<span class="lineno" id="38">    38  </span>	 * @param w (Number) image width
<span class="lineno" id="39">    39  </span>	 * @param h (Number) image height
<span class="lineno" id="40">    40  </span>	 * @param color (Number) box hexadecimal color
<span class="lineno" id="41">    41  </span>	 * @param color2 (Number) spinner &amp; border hexadecimal color	
<span class="lineno" id="42">    42  </span>	 * @param alpha (Number) box alpha
<span class="lineno" id="43">    43  </span>	 * @param border (Boolean) display border
<span class="lineno" id="44">    44  </span>	 * @param cb (Function) optional callback function		
<span class="lineno" id="45">    45  </span>	 * @return Void
<span class="lineno" id="46">    46  </span>	 * 
<span class="lineno" id="47">    47  </span>	 * {@code Usage:
<span class="lineno" id="48">    48  </span>	 * myMc.load("test.jpg", 160, 120, 0x242424, 0x99abc1, 80, true, cb);
<span class="lineno" id="49">    49  </span>	 * }
<span class="lineno" id="50">    50  </span>	 */</span>
<span class="lineno" id="51">    51  </span>	<span class="key">public</span> <span class="key">function</span> load(uri:String, w:Number, h:Number, color:Number, color2:Number, alpha:Number, border:Boolean, cb:Function):Void {
<span class="lineno" id="52">    52  </span>		_this.setup( w, h, color, color2, alpha, border );
<span class="lineno" id="53">    53  </span>		_this.init( uri, cb );
<span class="lineno" id="54">    54  </span>	}
<span class="lineno" id="55">    55  </span><span class="lineno" id="56">    56  </span>	<span class="comment doc">/**
<span class="lineno" id="57">    57  </span>	 * draw a rectangle (various init options)
<span class="lineno" id="58">    58  </span>	 * @param w (Number) image width
<span class="lineno" id="59">    59  </span>	 * @param h (Number) image height
<span class="lineno" id="60">    60  </span>	 * @param color (Number) box hexadecimal color
<span class="lineno" id="61">    61  </span>	 * @param color2 (Number) spinner &amp; border hexadecimal color	
<span class="lineno" id="62">    62  </span>	 * @param alpha (Number) box alpha
<span class="lineno" id="63">    63  </span>	 * @param border (Boolean) display border
<span class="lineno" id="64">    64  </span>	 * @return Void
<span class="lineno" id="65">    65  </span>	 * 
<span class="lineno" id="66">    66  </span>	 * {@code Usage:
<span class="lineno" id="67">    67  </span>	 * myMc.setup(160, 120, 0x242424, 0x99abc1, 80, true);
<span class="lineno" id="68">    68  </span>	 * }
<span class="lineno" id="69">    69  </span>	 */</span>
<span class="lineno" id="70">    70  </span>	<span class="key">public</span> <span class="key">function</span> setup(w:Number, h:Number, color:Number, color2:Number, alpha:Number, border:Boolean):Void {
<span class="lineno" id="71">    71  </span>		<span class="comment">// make instance reusable</span>
<span class="lineno" id="72">    72  </span>		<span class="key">if</span> (_this.box != undefined) {
<span class="lineno" id="73">    73  </span>			_this.box.removeMovieClip( );
<span class="lineno" id="74">    74  </span>		}
<span class="lineno" id="75">    75  </span>		<span class="key">if</span> (_this.img != undefined) {
<span class="lineno" id="76">    76  </span>			_this.img.removeMovieClip( );
<span class="lineno" id="77">    77  </span>		}
<span class="lineno" id="78">    78  </span>		_this.createEmptyMovieClip( <span class="str_const">"img"</span>, _this.getNextHighestDepth( ) );
<span class="lineno" id="79">    79  </span>		<span class="comment">// create box &amp; enable spinner if a box color was passed</span>
<span class="lineno" id="80">    80  </span>		<span class="key">if</span> (color) {
<span class="lineno" id="81">    81  </span>			_this.createEmptyMovieClip( <span class="str_const">"box"</span>, _this.getNextHighestDepth( ) );
<span class="lineno" id="82">    82  </span>			<span class="key">var</span> c:Number = (color) ? color : 0xFFFFFF;
<span class="lineno" id="83">    83  </span>			<span class="key">var</span> a:Number = (alpha) ? alpha : <span class="num_const">100</span>;
<span class="lineno" id="84">    84  </span>			<span class="key">var</span> lw:Number = (border) ? <span class="num_const">1</span> : <span class="num_const">0</span>;
<span class="lineno" id="85">    85  </span>			<span class="key">var</span> c2:Number = (color2) ? color2 : 0x000000;
<span class="lineno" id="86">    86  </span>			<span class="comment">// offset for 1px border</span>
<span class="lineno" id="87">    87  </span>			<span class="key">if</span> (lw == <span class="num_const">1</span>) {
<span class="lineno" id="88">    88  </span>				w += lw;
<span class="lineno" id="89">    89  </span>				h += lw;
<span class="lineno" id="90">    90  </span>				_this.img._x += lw;
<span class="lineno" id="91">    91  </span>				_this.img._y += lw;
<span class="lineno" id="92">    92  </span>			}
<span class="lineno" id="93">    93  </span>			<span class="key">if</span> (border) {
<span class="lineno" id="94">    94  </span>				box.lineStyle( lw, c2, a );
<span class="lineno" id="95">    95  </span>			}
<span class="lineno" id="96">    96  </span>			box.beginFill( c, a );
<span class="lineno" id="97">    97  </span>			box.moveTo( <span class="num_const">0</span>, <span class="num_const">0</span> );
<span class="lineno" id="98">    98  </span>			box.lineTo( w, <span class="num_const">0</span> );
<span class="lineno" id="99">    99  </span>			box.lineTo( w, h );
<span class="lineno" id="100">   100  </span>			box.lineTo( <span class="num_const">0</span>, h );
<span class="lineno" id="101">   101  </span>			box.endFill( );
<span class="lineno" id="102">   102  </span>		}
<span class="lineno" id="103">   103  </span>		<span class="comment">// setup spinner                                                           </span>
<span class="lineno" id="104">   104  </span>		_this.spinner._x = int( (w / <span class="num_const">2</span>) );
<span class="lineno" id="105">   105  </span>		_this.spinner._y = int( (h / <span class="num_const">2</span>) );
<span class="lineno" id="106">   106  </span>		Tweener.addTween(_this.spinner, {_color:c2, time:<span class="num_const">0</span>});
<span class="lineno" id="107">   107  </span>	}
<span class="lineno" id="108">   108  </span><span class="lineno" id="109">   109  </span>	<span class="comment doc">/**
<span class="lineno" id="110">   110  </span>	 * load an image after setup has been called
<span class="lineno" id="111">   111  </span>	 * @param uri (String) image uri
<span class="lineno" id="112">   112  </span>	 * @param cb (Function) optional callback function
<span class="lineno" id="113">   113  </span>	 * @return Void
<span class="lineno" id="114">   114  </span>	 * 
<span class="lineno" id="115">   115  </span>	 * {@code Usage:
<span class="lineno" id="116">   116  </span>	 * myMc.init ("test.jpg", cb);
<span class="lineno" id="117">   117  </span>	 * }
<span class="lineno" id="118">   118  </span>	 */</span>
<span class="lineno" id="119">   119  </span>	<span class="key">public</span> <span class="key">function</span> init(uri:String, cb:Function):Void {
<span class="lineno" id="120">   120  </span>		_this.img.unloadMovie( );
<span class="lineno" id="121">   121  </span>		_this.img._alpha = <span class="num_const">0</span>;
<span class="lineno" id="122">   122  </span>		_this.img.swapDepths( _this.getNextHighestDepth( ) );
<span class="lineno" id="123">   123  </span>		_this.spinner.swapDepths( _this.getNextHighestDepth( ) );
<span class="lineno" id="124">   124  </span>		_this.img.loadMovie( uri );
<span class="lineno" id="125">   125  </span>		_this.spinner._visible = <span class="key">true</span>;
<span class="lineno" id="126">   126  </span>		_this.spinner._alpha = <span class="num_const">100</span>;
<span class="lineno" id="127">   127  </span>		<span class="key">delete</span> _this.spinner.onEnterFrame;
<span class="lineno" id="128">   128  </span>		_this.spinner.onEnterFrame = <span class="key">function</span> ():Void {
<span class="lineno" id="129">   129  </span>			<span class="key">this</span>._rotation -= <span class="num_const">20</span>;
<span class="lineno" id="130">   130  </span>		};
<span class="lineno" id="131">   131  </span>		_this.onEnterFrame = <span class="key">function</span> ():Void {
<span class="lineno" id="132">   132  </span>			<span class="key">var</span> l:Number = _this.img.getBytesLoaded( );
<span class="lineno" id="133">   133  </span>			<span class="key">var</span> t:Number = _this.img.getBytesTotal( );
<span class="lineno" id="134">   134  </span>			<span class="key">if</span> (l &gt;= t &amp;&amp; t &gt; <span class="num_const">5</span>) {
<span class="lineno" id="135">   135  </span>				<span class="key">delete</span> _this.onEnterFrame;
<span class="lineno" id="136">   136  </span>				Tweener.removeTweens(_this.img);
<span class="lineno" id="137">   137  </span>				Tweener.removeTweens(_this.spinner);
<span class="lineno" id="138">   138  </span>				_this.img._alpha = <span class="num_const">0</span>;
<span class="lineno" id="139">   139  </span>				_this.spinner._alpha = <span class="num_const">100</span>;
<span class="lineno" id="140">   140  </span>				Tweener.addTween(_this.img, {_alpha:<span class="num_const">100</span>, time:<span class="num_const">0</span>.<span class="num_const">6</span>, delay:<span class="num_const">0</span>.<span class="num_const">1</span>, transition:Mot.io.quad});
<span class="lineno" id="141">   141  </span>				<span class="key">var</span> spinCb:Function = <span class="key">function</span> ():Void {
<span class="lineno" id="142">   142  </span>					<span class="key">delete</span> _this.spinner.onEnterFrame;
<span class="lineno" id="143">   143  </span>					_this.spinner._visible = <span class="key">false</span>;
<span class="lineno" id="144">   144  </span>					_this.spinner._alpha = <span class="num_const">100</span>;
<span class="lineno" id="145">   145  </span>				};
<span class="lineno" id="146">   146  </span>				Tweener.addTween(_this.spinner, {_alpha:<span class="num_const">0</span>, time:<span class="num_const">0</span>.<span class="num_const">5</span>, delay:<span class="num_const">0</span>.<span class="num_const">3</span>, transition:Mot.o.quint, onComplete:Delegate.create(_this, spinCb)});
<span class="lineno" id="147">   147  </span>				<span class="key">if</span> (cb) {
<span class="lineno" id="148">   148  </span>					cb( );
<span class="lineno" id="149">   149  </span>				}
<span class="lineno" id="150">   150  </span>			}
<span class="lineno" id="151">   151  </span>		};
<span class="lineno" id="152">   152  </span>	}
<span class="lineno" id="153">   153  </span>}</pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package com.sekati.ui" class="button">Package</a></li><li><a href="Image.html" title="Detail of com.sekati.ui.Image API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>